#include "checksum.h"

uint8_t
isValidChecksum(
    uint8_t* data, 
	uint8_t length, 
	uint8_t checksum)
{
	uint8_t actualChecksum =
	    constructChecksum(data, length);

    if (checksum == actualChecksum)
	    return 1;
    else
	    return 0;
}

uint8_t
constructChecksum(
    uint8_t* data,
	uint8_t length)
{
    // Construct a checksum by XORing all bytes of data
    uint8_t checksum = 0x00; {
        uint8_t i;
        for (i = 0; i < length; ++i) {
            checksum ^= data[i];
        }
    }

    return checksum;
}
